package com.ran.jdbc;

import java.io.InputStream;
import java.sql.*;
import java.util.Properties;


public class JDBCUtils {

	private final static String DRIVER="com.mysql.cj.jdbc.Driver";
	private final static String URL ="jdbc:mysql://115.120.245.212:3306/linux_exam";  //改成自己数据库名
	private final static String DB_USER="root2";
	private final static String DB_PASSWORD="1qaz@WSX#EDC";
	

	public static Connection getConnection() throws Exception {
		Class.forName(DRIVER);
		Connection conn = DriverManager.getConnection(URL, DB_USER,DB_PASSWORD);
		return conn;
	}

	public static void closeResource(Connection conn,Statement ps){
		try {
			if(ps != null)
				ps.close();
		} catch (SQLException e) {
			e.printStackTrace();
		}
		try {
			if(conn != null)
				conn.close();
		} catch (SQLException e) {
			e.printStackTrace();
		}
	}

	public static void closeResource(Connection conn,Statement ps,ResultSet rs){
		try {
			if(ps != null)
				ps.close();
		} catch (SQLException e) {
			e.printStackTrace();
		}
		try {
			if(conn != null)
				conn.close();
		} catch (SQLException e) {
			e.printStackTrace();
		}
		try {
			if(rs != null)
				rs.close();
		} catch (SQLException e) {
			e.printStackTrace();
		}
	}



}
